<template>
    <div class="conversation-item-container"
         @click="showConversation"
         @contextmenu.prevent="showConversationInfoContextMenu"
         v-bind:class="{
             drag: dragAndDropEnterCount > 0,
             active: shareConversationState.currentConversationInfo&&source&&(shareConversationState.currentConversationInfo.from==source.from),
             top:source.top,
             highlight:shareConversationState.contextMenuConversationInfo
         }"
         >
        <div class="conversation-item">
            <div class="header">
                <img  v-if="source.img" class="avatar" draggable="false" :src="source.avatar" alt=""
                     />
                <Blockies v-else class="border_radius" :seed="source.from" :size="18" :scale="2" spotcolor="#000" />
                <em v-if="unread > 0" class="badge">{{ unread > 99 ? '···' : unread }}</em>
            </div>
            <div class="content-container">
                <div class="title-time-container">
                    <div class="title">{{ splitAddress(source.from)  }}</div>
                    <i v-if="source.type === 5" class="icon-ion-android-lock" style="padding-right: 5px"></i>
                    <p class="time single-line">{{ source.time }}</p>
                </div>
                <div class="content">
                    <p class="draft single-line" v-if="source.draft" v-html="draft"></p>
                    <p class="last-message-desc single-line" v-else>
                        <i v-if="source.unreadMention > 0">[有人@我]</i>
                        {{ source.value }}
                    </p>
                    <i v-if="source.isSilent" class="icon-ion-android-notifications-off"></i>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { splitAddress } from "@/utils/index.js";
import store from "../../../store";
import Config from "../../../config";
export default {
    name: "ConversationItemView",
    props: {
        source: {
            type: Object,
            required: true,
        },
    },
    data() {
        return {
            dragAndDropEnterCount: 0,
            splitAddress,
            shareConversationState: store.state.conversation,
            groupPortrait: Config.DEFAULT_GROUP_PORTRAIT_URL,
        };
    },
    mounted() {
        // this.refreshGroupPortrait();
    },
    methods: {
        showConversation() {
            // 展示arguments点击进入聊天
            store.setCurrentConversationInfo(this.source);
        },
        showConversationInfoContextMenu(event) {
            this.$eventBus.$emit('showConversationContextMenu', [event, this.source]);
        },
    },
    computed: {
        unread(){
            return 0
        }
    },
};
</script>

<style scoped>
.conversation-item-container {
    padding-left: 12px;
    background-color: #f8f8f8;
}

.conversation-item-container.drag {
    border: 1px solid #4168e0;
}

.conversation-item-container.active {
    background-color: #DEDEDE;
}

.conversation-item-container.top {
    background-color: #EBEBEB;
}

.conversation-item-container.highlight {
    box-shadow: 0 0 0 1px #4168e0 inset;
    z-index: 100;
}

.conversation-item-container.active.top {
    background-color: #D3D3D3;
}

.conversation-item {
    width: 100%;
    height: 68px;
    display: flex;
    /*border-bottom: 1px solid #eeeeee;*/
    align-items: center;
    justify-content: center;
}

.header {
    height: 100%;
    padding: 10px 12px 10px 0;
    margin-right: 2px;
    position: relative;
}

.header .avatar {
    position: relative;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    background: #d6d6d6;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 3px;
}

.header .badge {
    position: absolute;
    color: white;
    font-size: 10px;
    background-color: red;
    border-radius: 8px;
    min-width: 16px;
    height: 16px;
    padding: 0 5px;
    line-height: 16px;
    font-style: normal;
    text-align: center;
    right: 8px;
    top: 8px;
    vertical-align: center;
}

.header .badge.silent {
    width: 8px;
    height: 8px;
    min-width: 8px;
    padding: 0;
    font-size: 0;
}

.content-container {
    width: 100%;
    height: 45px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding-right: 12px;
}

.content-container .title-time-container {
    display: flex;
    width: 100%;
    max-width: 100%;
    align-content: center;
    justify-content: space-between;
}

.content-container .title-time-container .title {
    display: inline-block;
    font-size: 14px;
    color: #262626;
    font-style: normal;
    font-weight: normal;
    flex: 1;
}

.content-container .title-time-container .time {
    display: inline-block;
    color: gray;
    font-size: 10px;
}

.content-container .content {
    display: flex;
    justify-content: space-between;
}

.content .draft {
    font-size: 12px;
    height: 20px;
    color: #b8b8b8;
}

/*refer to: https://blog.csdn.net/weixin_42412046/article/details/80804285*/
>>> .content .draft em {
    color: red;
    font-style: normal;
    padding-right: 5px;
}

.conversation-item-container.top .content .last-message-desc {
    color: #949494;
}

.content .last-message-desc {
    color: #ACACAC;
    font-size: 12px;
}

.content .last-message-desc i {
    font-style: normal;
    color: red;
}

.content i {
    color: #b8b8b8;
}


</style>
